WooCommerce: Display Advanced Custom Fields @ Single Product

您所在的位置:网站首页 product page 17 WooCommerce: Display Advanced Custom Fields @ Single Product

WooCommerce: Display Advanced Custom Fields @ Single Product

#WooCommerce: Display Advanced Custom Fields @ Single Product| 来源: 网络整理| 查看: 265

WooCommerce: Display Advanced Custom Fields @ Single Product > Published: Mar 2017 - Revised: Mar 2019 > Blog Category: WooCommerce Tips > Blog Tags: ACF, Price > Blog Comments: 64 Comments Tweet

Join 17,000+ WooWeekly subscribers

Advanced Custom Fields plugin is a great way to add custom, advanced fields to the WooCommerce Single Product Page. Many struggle to display such fields on the front-end, so this simple snippet should help you!

WooCommerce: display Advanced Custom Field @ single product page PHP Snippet: Display Advanced Custom Fields @ WooCommerce Single Product Page /** * @snippet Display Advanced Custom Fields @ Single Product - WooCommerce * @how-to Get CustomizeWoo.com FREE * @sourcecode https://businessbloomer.com/?p=22015 * @author Rodolfo Melogli * @compatible WooCommerce 3.5.7 * @donate $9 https://businessbloomer.com/bloomer-armada/ */ add_action( 'woocommerce_product_thumbnails', 'bbloomer_display_acf_field_under_images', 30 ); function bbloomer_display_acf_field_under_images() { echo 'Trade Price: ' . get_field('trade'); // Note: 'trade' is the slug of the ACF } Related posts: WooCommerce: Display Regular & Sale Price @ Cart Table In my opinion, the WooCommerce Cart table is somewhat confusing. Why isn’t the “sale price” displayed there? Well, this is... WooCommerce: Add Custom Product Fields (e.g. RRP) Without a Plugin The manufacturer’s suggested retail price (MSRP), or the recommended retail price (RRP), is the price at which the manufacturer recommends... WooCommerce: Display Cart Item Subtotal With Coupon Discount This is a nice follow up from last week’s snippet “WooCommerce: Slashed Cart Subtotal if Coupon @ Cart“, where I... Where to add custom code?

You should place PHP snippets at the bottom of your child theme functions.php file and CSS at the bottom of its style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my guide "Should I Add Custom Code Via WP Editor, FTP or Code Snippets?" and my video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?Please let me know in the comments if everything went as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting.

If you think this code saved you time & money, feel free to join 17,000+ WooCommerce Weekly subscribers for blog post updates and 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance!

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

Follow @rmelogli Category: WooCommerce Tips Tags: ACF, Price 64 thoughts on “WooCommerce: Display Advanced Custom Fields @ Single Product” Diiamo September 10, 2022

Hi, I use the below code to display the ACF field at the bottom of the product archive, but it doesn’t work.

Reply Diiamo September 10, 2022

I google and find the alternative code, it works well on my site. Hope can help anyone who needs it. Replace the “seoct” only with your ACF field name.

add_action( ‘woocommerce_after_shop_loop’, ‘diiamo_display_acf_field_under_product’, 11); function diiamo_display_acf_field_under_product() { $term = get_queried_object(); $seo_content = get_field(‘seoct’, $term); if( !empty($seo_content) ) { echo ” . $seo_content . ”; } } Reply sobhan May 9, 2021

thank you thats right in medilink theme

Reply Rodolfo Melogli June 2, 2021

Cool

Reply Savvas March 4, 2021

Hi and thank you very much for that snippet. It works fine fo me but i have a problem with title. If none of the fields have value it is not showing up but the title does. How i can hide the title “SPECIFICATIONS” if one of the fileds have value ?

add_action( 'woocommerce_product_meta_end', 'bbloomer_display_acf_field_under_images', 40 ); function bbloomer_display_acf_field_under_images() { echo ""; echo 'SPECIFICATIONS'; echo ""; if( get_field('net_weight') ): echo 'Net weight: ' . get_field('net_weight'); echo ""; endif; if( get_field('sealing') ): echo 'Sealing: ' . get_field('sealing'); echo ""; endif; . . . etc .......

thanks in advance .

Reply Savvas March 4, 2021

sorry i mean “if none of the fileds have value”….

Reply Rodolfo Melogli March 11, 2021

You’re already checking if those fields exist below, right? Simply add another check on top, to see if one OR the other exist

Reply Fabrizio January 2, 2021

Hi Rodolfo, your blog is really great. I’ve found many interesting posts. I’ve inserted your script in my function.php and it works. But it works only if my custom field is a Editor Wysiwyg field type. But if my custom field is a checkbox? How can I modify your script? I tried to change get_field with the_field but it doesn’t work. Thanks.

Reply Rodolfo Melogli February 6, 2021

Hi Fabrizio, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

Reply Aziz September 2, 2020

How do I show advanced custom field in an existing single product tab? please reply. Thanks

Reply Rodolfo Melogli September 10, 2020

Hi Aziz, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

Reply Jonas April 28, 2020

Hi there, thanks for sharing this great snippet! I was just wondering if it’s somehow possible to only show the ACF field if it has got a value? I reckon that would be really useful… Also, is it easy to change to code to show a standard custom field? Many thanks for your help!

Reply Rodolfo Melogli April 29, 2020

Hi Jonas, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

Reply Whitney February 15, 2020

Hello, is there a way to get these fields to display after the product meta information instead of after the photo?

Using this PHP line to get my other fields to display, and they are working properly but I would like my ACF to appear under them…

Reply Rodolfo Melogli February 22, 2020

Hello Whitney, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

Reply kelly January 24, 2020

Hi, thanks so much for this! Is there a way I can display custom taxonomies too?

Reply kelly January 24, 2020

Also, is there any way I can wrap each custom field in a div?

Reply Rodolfo Melogli January 25, 2020

Hi Kelly, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

Reply Ahmet January 18, 2020

Hello Rodolfo, it still working fine. I just couldn’t handle show up prepend and append values on frontend. Could you please guide an example for us? Thank you so much.

Reply Rodolfo Melogli January 20, 2020

Hi Ahmet, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

Reply Brian September 24, 2019

Hi, Rodolfo

Thanks for the snippet! Do you happen to have one for displaying custom fields for a variable product? I have custom field for the variations, but can’t get them to display on the product page.

thnx in advance!

Reply Rodolfo Melogli September 25, 2019

I don’t, sorry

Reply Andrew Turner August 17, 2019

Hi, It would be great if you could do a tutorial for adding ACF fields to the checkout page too.

Reply Rodolfo Melogli August 21, 2019

I’ll think about it. Thank you

Reply Kostas August 6, 2019

Works great on Aug 6, 2019. Thank you!

Reply Rodolfo Melogli August 12, 2019

Excellent!

Reply Juraj August 6, 2019

Hi Rodolfo, thanks for this tutorial 🙂

Can You explain how to display field in product only if product is marked as “featured”?

Reply Rodolfo Melogli August 12, 2019

Hello Juraj, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

Reply amy March 24, 2019

Not working. THis is what i added to the functions/php in my snippet plugin. Please advise.

/** * @snippet Display Advanced Custom Fields @ Single Product - WooCommerce * @how-to Get CustomizeWoo.com FREE * @sourcecode https://businessbloomer.com/?p=22015 * @author Rodolfo Melogli * @testedwith WooCommerce 2.5.2 */ add_action( 'woocommerce_product_thumbnails', 'bbloomer_display_acf_field_under_images', 30 ); function bbloomer_display_acf_field_under_images() { echo 'Specs: ' . get_field('wattage'); echo 'Specs: ' . get_field('voltage'); echo 'Specs: ' . get_field('flange_size'); echo 'Specs: ' . get_field('immersion_length'); echo 'Specs: ' . get_field('includes'); // Note: 'trade' is the slug of the ACF } Reply Rodolfo Melogli March 28, 2019

Not sure Amy, is ACF set up properly? Works for me.

Reply a_grant85 March 17, 2019

It still works, thanks so much, I spent hours trying to solve this! 🙂

Reply Rodolfo Melogli March 28, 2019

Fantastic!

Reply woodenbetonit February 10, 2019

Hi there, I am running Woocomerce and WC Vendors, and have managed to create a custom field “ISBN Number” on my Product Page to enter a ISBN Number.

I want, no need it to show on an individual product page and be searchable. I have attempted the code on this page and on https://businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/ to add the visual hook, but still can’t see it after adding to the functions.php

Unless it is not obvious, I am am not a dev haha! please help!

Reply Rodolfo Melogli February 14, 2019

Hello there, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

Reply Andrea Straughn November 28, 2018

How can i change the font of the field that is displayed?

Reply Rodolfo Melogli December 5, 2018

Andrea, thanks for your comment! You’ll need custom CSS for that 🙂

Reply Jaco Cloete November 6, 2018

I can output single field without a problem but can someone tell me how my code should look if I have these repeater fields which are arrays.

Training Price:R Excl VAT Course Duration: Days CPD Points: Points Course Dates (You must select a date listed here to enable form submit) Johannesburg


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3